//
//  CJAllForwardController.m
//  Boss
//
//  Created by admin on 2018/9/20.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "CJAllForwardController.h"
#import "CJForwardRevenusCell.h"
@interface CJAllForwardController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)NSMutableArray *dataArray;
@property (nonatomic)NSUInteger page1;
@property (nonatomic,strong)UITableView *tableView;
@end

@implementation CJAllForwardController
-(NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    self.page1 = 1;
    [self loadData];
    WEAKSELF
    self.tableView.mj_footer=[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        // weakSelf.refresh=NO;
        weakSelf.page1++;
        // [weakSelf loadTableData];
        [weakSelf loadData];
    }];
   
    
    
}
-(void)loadData
{
    WEAKSELF
    NSString *page = [NSString stringWithFormat:@"%ld",self.page1];
    [WYHttpServer getTransferListWithCurrentPage:page WithPageSize:@"20" WithType:nil SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            [weakSelf.dataArray addObjectsFromArray:[CJForwardRevenusModel getForwardRevenusModelFromJson:response[@"result"][@"detail"]]];
            [weakSelf.tableView reloadData];
            if ([response[@"result"][@"hasNextPage"] integerValue]) {
                [weakSelf.tableView.mj_footer endRefreshing];
            }else{
                [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
            }
        }else{
            [weakSelf toast:errorMessage];
        }
    }];
}

-(void)setupUI
{
    self.navigationItem.title = @"转发中收益";
    [self.view addSubview:self.tableView];
    self.tableView.rowHeight = 73;
    [self.tableView registerNib:[UINib nibWithNibName:@"CJForwardRevenusCell" bundle:nil] forCellReuseIdentifier:@"CJForwardRevenusCell"];
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
   // return 10;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CJForwardRevenusCell *cell =[tableView dequeueReusableCellWithIdentifier:@"CJForwardRevenusCell" forIndexPath:indexPath];
    if (!cell) {
        cell =[[NSBundle mainBundle]loadNibNamed:@"CJForwardRevenusCell" owner:nil options:nil].firstObject;
    }
    CJForwardRevenusModel *model = self.dataArray[indexPath.row];
    [cell setModel:model];

    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
 
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.000001;
}

- (UITableView *)tableView
{
    if (_tableView == nil) {
        CGRect frame = CGRectMake(0, self.navHeight, kScreenWidth, kScreenHeight-self.navHeight);
        _tableView = [[UITableView alloc] initWithFrame:frame
                                                  style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
    }
    return _tableView;
}







@end
